package com.xkxx.task.controller;

import com.xkxx.task.entity.BatchData;
import com.xkxx.task.model.ResultApi;
import com.xkxx.task.service.BatchDataService;
import com.xkxx.task.service.BusinessDataService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: K-9999
 * @Date: 2022/12/15
 * @Description:
 */
@RestController
@RequestMapping("/api/batchData")
public class BatchDataController {

    private Logger log = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private BatchDataService batchDataService;

    @Autowired
    private BusinessDataService businessDataService;

    @PostMapping("/sendData")
    public ResultApi sendData(@RequestBody BatchData data){
        BatchData batchData = batchDataService.getBatchData(data.getAppId(), data.getBatchNo());
        if (batchData != null) {
            //update
            log.info("更新数据");
            //TODO 更新businessData
            return ResultApi.instanceSuccess(batchDataService.updateBatchData(batchData.getId(), data));
        } else {
            //insert
            log.info("新增数据");
            //TODO 更新businessData
            return ResultApi.instanceSuccess(batchDataService.addBatchData(data));
        }

    }
}
